lesia.register({
	name: 'lesia.Data.Context',
	require: ['lesia.Data.DataSet', 
	          'lesia.Data.Bar', 
	          'lesia.Events.EventTarget']
}, function (l, DataSet, Item, EventTarget) {
	/**
	 * Creates a context of DataSet
	 *
	 * @constructor
	 * @extend lesia.Events.EventTarget
	 */
	var Context = function (dataSet, interval) {
		
		//sets interval
		//readonly
		Object.defineProperty(this, 'interval', {
			value: interval
		});
		
		this._setDataSet(dataset);
	};
	
	
	l.extend(Context, EventTarget);
	
	/**
	 * Event Types
	 */
	Context.EventTypes = Context.prototype.EventTypes = {
		TICK: 'tick',
		OPEN: 'open',
		CLOSE: 'close'
	};
	
	
	/**
	 * Consists timestamp for last item in the dataSet
	 * @type {Number}
	 */
	Object.defineProperty(Context.prototype, 'timestamp', {
		get: function () {
			return this._dataSet.lastRecord.timeStamp;
		}
	});
	
	/**
	 * Consists last item in 
	 */
	Object.defineProperty(Context.prototype, 'lastItem', {
		get: function () {
			//get timestamp of last item in the dataset
			var itemLength = this.timestamp % (this.interval * 1000);
			return new Item(DataSet.getItems(this.timestamp - itemLength));
		}
	});
	
	
	/**
	 * @protected
	 */
	Context.prototype._setDataSet = function (dataSet) {
		this._dataSet = dataSet;
		
		//TODO think about listeners
		dataSet.addEventListener(dataSet.EventTypes.DATA, this._handleNewData, this);
	};
	
	/**
	 * 
	 */
	Context.prototype.dispose = function () {
		delete this._dataSet;
	};
	
	
	Context.create = function (dataSet, timeFrame) {
		
	};
	
	return Context;
});